Security News
GitHub Removes Malicious Pull Requests Targeting Open Source Repositories
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
fetch-blob
Advanced tools
The fetch-blob npm package is a module that allows you to work with Blob data in a way that is consistent with the browser's Fetch API. It provides a way to create, read, and manipulate binary data in Node.js, which can be useful for tasks such as file uploads, image processing, and other operations that involve handling raw binary data.
Creating a Blob
This feature allows you to create a new Blob object from raw data. The example code creates a Blob containing the text 'Hello, world!' with a MIME type of 'text/plain'.
const { Blob } = require('fetch-blob');
const blob = new Blob(['Hello, world!'], { type: 'text/plain' });
Reading a Blob as text
This feature allows you to read the contents of a Blob as text. The example code reads the text from the Blob and logs it to the console.
const { Blob } = require('fetch-blob');
const blob = new Blob(['Hello, world!'], { type: 'text/plain' });
blob.text().then((text) => {
console.log(text); // Outputs: Hello, world!
});
Reading a Blob as a Buffer
This feature allows you to read the contents of a Blob as an ArrayBuffer, which can then be converted to a Node.js Buffer. The example code demonstrates how to convert the ArrayBuffer to a Buffer and log it to the console.
const { Blob } = require('fetch-blob');
const blob = new Blob(['Hello, world!'], { type: 'text/plain' });
blob.arrayBuffer().then((buffer) => {
const nodeBuffer = Buffer.from(buffer);
console.log(nodeBuffer); // Outputs: <Buffer 48 65 6c 6c 6f 2c 20 77 6f 72 6c 64 21>
});
The 'blob' package is another implementation of the Blob object for Node.js. It is similar to fetch-blob but may have differences in API and supported features.
The 'form-data' package allows you to create `multipart/form-data` streams that can be used for submitting forms and file uploads in Node.js. It is similar to fetch-blob in that it deals with binary data, but it is more focused on form submission and multipart data.
The 'buffer' package is a Node.js core module that provides a way to handle binary data. While not a direct alternative to fetch-blob, it is often used in conjunction with other modules to handle binary data in Node.js applications.
A Blob implementation in Node.js, originally from node-fetch.
npm install fetch-blob
const Blob = require('fetch-blob');
const fetch = require('node-fetch');
fetch('https://httpbin.org/post', {
method: 'POST',
body: new Blob(['Hello World'], { type: 'text/plain' })
})
.then(res => res.json());
.then(json => console.log(json));
See the MDN documentation and tests for more details.
FAQs
Blob & File implementation in Node.js, originally from node-fetch.
The npm package fetch-blob receives a total of 2,162,041 weekly downloads. As such, fetch-blob popularity was classified as popular.
We found that fetch-blob demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
GitHub removed 27 malicious pull requests attempting to inject harmful code across multiple open source repositories, in another round of low-effort attacks.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.